package model;

import java.text.SimpleDateFormat;
import java.util.Date;

import javax.swing.JOptionPane;

public class LigneReservation {
	private CategorieChambre catChambre;
	private Date dateArrive,
					dateDepart;
	private int quantite;
	private boolean sejourCree = false;
	
	public LigneReservation(CategorieChambre catChambre, Date arrive, Date depart, int quantite) {
		this.catChambre = catChambre;
		dateArrive = arrive;
		dateDepart = depart;
		this.setQuantite(quantite);
	}

	/**
	 * @return la catChambre
	 */
	public CategorieChambre getCategorieChambre() {
		return catChambre;
	}

	/**
	 * @return la dateArrive
	 */
	public Date getDateArrive() {
		return dateArrive;
	}

	/**
	 * @return la dateDepart
	 */
	public Date getDateDepart() {
		return dateDepart;
	}
	
	/**
	 * @return la quantite
	 */
	public int getQuantite() {
		return quantite;
	}


	/**
	 * @param chambre la chambre a enregistrer
	 */
	public void setCategorieChambre(CategorieChambre catChambre) {
		this.catChambre = catChambre;
	}

	/**
	 * @param dateArrive la dateArrive a enregistrer
	 */
	public void setDateArrive(Date dateArrive) {
		this.dateArrive = dateArrive;
	}

	/**
	 * @param dateDepart la dateDepart a enregistrer
	 */
	public void setDateDepart(Date dateDepart) {
		if (dateArrive.getTime() > dateDepart.getTime()){
			this.dateDepart = dateDepart;
		} 
		else {
			JOptionPane.showMessageDialog(null, "Date de depart precede la date d'arrivee", "Attention", JOptionPane.ERROR_MESSAGE);
		}
	}
	
	/**
	 * @param quantite
	 */
	public void setQuantite(int quantite) {
		this.quantite = quantite;
	}
	
	public String toStringFormat(){
		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");		
		String ligneReservationFormatte = this.catChambre.getCategorie();
		
		ligneReservationFormatte += " " + this.quantite;
		
		ligneReservationFormatte += " " + dateFormat.format(dateArrive) + " " + dateFormat.format(dateDepart);
		
		return ligneReservationFormatte;
	}

	public boolean isSejourCree() {
		return sejourCree;
	}

	public void setSejourCree(boolean sejourCree) {
		this.sejourCree = sejourCree;
	}
}
